﻿<?php
include ("../conn.php");
$sql="select * from news";
$query=mysqli_query($con,$sql);
if($_GET['del']=="yes"&&$_GET['newsid'])
{
	//echo "<script>onClick='if(!confirm('删除吗')){return false}else{return true}'</script>";
	$delsql='delete from news where id='.$_GET['newsid'].'';
	mysqli_query($con,$delsql);
	echo "删除成功!<a href=editnews.php>返回</a>";
	exit;
}
if($_GET['title']){
	echo $uptitle=$_GET['title'];
	$upcontent=$_GET['content'];
	$upsql='UPDATE news SET title="'.$uptitle.'",content="'.$upcontent.'" WHERE id='.$_GET['nid'].'';
	mysqli_query($con,$upsql);
}
//echo $upsql; 打印sql语句
if($newsid=$_GET['newsid'])
{
	$sql='select * from news where id="'.$newsid.'"';
	$query=mysqli_query($con,$sql);
	$row=mysqli_fetch_array($query,MYSQLI_ASSOC);
?>
<form name=myform  method=GET action="">
	标题：<input type=text name=title value= <?php echo $row['title'];?> /><br />
	<input type=hidden name=nid value=<?php echo $row['id']?>>
	内容：<br /><textarea name=content cols=50 rows=14><?php echo $row['content'];?></textarea>
	<br /><input value=修改 type=submit name=submit>
</form>
<?php
}
//$row=mysql_fetch_array($query);
//print_r($row);
?>

  <div>
  	<ul>
      <?php
        while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
         {
      ?>
      <li><a href=?newsid=<?php echo $row['id'];?> ><?php echo $row['title'];?></a> <a href=?newsid=<?php echo $row['id'];?>&del=yes>删除</a></li>
      	<?php
      	 }
      	?>
  	</ul>
  </div>
